// 首页轮播
new Vue({

    data:{
        bannerSwiper:null
    },


    methods:{
        next:function(){
            this.bannerSwiper.swipeNext();
        },
        prev:function(){
            this.bannerSwiper.swipePrev();
        }
    },

    mounted: function () {
        this.bannerSwiper = this.$createSwiper(this.$el, {
            pagination: '.swiper-pagination',
            paginationClickable: true,
           // simulateTouch: false,
           //  nextButton: '.swiper-button-next',
           //  prevButton: '.swiper-button-prev',
            speed: 500,
            loop: true,
            autoplay: 5000, //可选选项，自动滑动
        })
    }

}).$mount('#index_banner_wrapper');



//产品服务轮播
new Vue({

    data:{
        swiper:null
    },


    methods:{
        next:function(){

            this.swiper.swipeNext();
        },
        prev:function(){
            this.swiper.swipePrev();
        }
    },

    mounted: function () {
        this.swiper = this.$createSwiper(this.$refs['product-sevice-swiper'], {
            slidesPerView: 4,
            paginationClickable: true,
            // nextButton: '#product_sevice .swiper-button-next',
            // prevButton: '#product_sevice .swiper-button-prev',
            loop: true,
            simulateTouch: false,
            spaceBetween: 10,
            autoplay: 5000, //可选选项，自动滑动
        })
    }

}).$mount('#product_sevice');


//新闻模块
new Vue({
    // http:{
    //     root:'http://bymadmin.me/'
    // },

    data:{
        currentTagId : 0,
        loading : true, //请求状态
        newsTags: [],
        newsList:[],
        newsSwiper:null
    },

    methods:{

        next:function(){
            this.newsSwiper.swipeNext();
        },
        prev:function(){
            this.newsSwiper.swipePrev();
        },


        getNewsList:function(){
            var self = this;
            if(!self.loading){
                self.loading = true;
                return self.$http.get('/api/web-page/news-article?page=1&per_page=8&tag_id='+ self.currentTagId ).then(function(responese){
                    if( responese.body.code !== 0 ){
                        throw Error('获取新闻摘要列表失败，code: '+responese.body.code)
                    }
                    self.newsList = responese.body['articles_paginate'].data;
                    self.loading = false;
                }).catch(function(error){
                    throw  error;
                })
            };
         },

        changeTag:function(id){
            this.currentTagId = id;
            this.getNewsList();
        }
    },


    mounted: function () {
        var self = this;
        //获取文章分类
        var p1 = self.$http.get('api/web-page/news-article/create').then(function(response){
            if( Number(response.body.code) !== 0 ){
                throw Error('获取新闻分类失败，code: '+response.body.code)
            }
            var newsCategory =  _.find(response.body.tags,function(el){
                return el.name === '新闻动态' ;
            });

            self.newsTags = newsCategory['sub_tag'];
            self.currentTagId = newsCategory['sub_tag'][0].id;
            self.loading = false; //本次加载完成
            return self.getNewsList();

        }).catch(function(error){
            throw  error;
        });

        p1.then(function(){
            this.newsSwiper = this.$createSwiper(this.$refs['news-swiper'], {
                // nextButton: '.news-banner-wrapper .swiper-button-next',
                // prevButton: '.news-banner-wrapper .swiper-button-prev',
                pagination: '.news-banner-wrapper .swiper-pagination',
                simulateTouch: false,
                slidesPerView: 1,
                paginationClickable: true,
                autoplay: 4000, //可选选项，自动滑动
                // observer:true,
                // loop: true
            })
        });

        
        //配置轮播插件

    }
}).$mount("#news");




